package com.guoxue.action.back;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.guoxue.domain.*;
import com.guoxue.service.IAdvertisementService;
import com.guoxue.service.IBookConfigService;
import com.guoxue.service.IChapterConfigService;
import com.guoxue.service.ICoinsService;
import com.guoxue.service.IDistrictService;
import com.guoxue.service.IExpertReadingService;
import com.guoxue.service.IExplainConfigService;
import com.guoxue.service.IFeedBackService;
import com.guoxue.service.IPlanChapterConfigService;
import com.guoxue.service.IPlanConfigService;
import com.guoxue.service.IPropertyConfigService;
import com.guoxue.service.IPublishLogsService;
import com.guoxue.service.IPushService;
import com.guoxue.service.IRecordConfigService;
import com.guoxue.service.IReportService;
import com.guoxue.service.IResourceService;
import com.guoxue.service.IShopConfigService;
import com.guoxue.service.IStageConfigService;
import com.guoxue.service.IStoryConfigService;
import com.guoxue.service.IUserService;
import com.guoxue.util.OSSUtil;
/**
 * 对应视图跳转数据加载
 * @author young
 *
 */
@Controller
@RequestMapping("View")
public class ViewAction {
	
	@Resource
	private IRecordConfigService recordServcie;
	@Resource
	private IBookConfigService bookServcie;
	@Resource
	private IChapterConfigService chapterService;
	@Resource
	private IExpertReadingService expertService;
	@Resource
	private IExplainConfigService explainService;
	@Resource
	private IPlanConfigService planConfigService;
	@Resource
	private IPropertyConfigService propertyConfigService;
	@Resource
	private IDistrictService districtService;
	@Resource
	private IStageConfigService stageConfigService;
	@Resource
	private IStoryConfigService storyService;
	@Resource
	private IUserService userService;
	@Resource
	private IPublishLogsService publishService;
	@Resource
	private IResourceService resourceService;
	@Resource
	private IReportService reportService;
	@Resource
	private IFeedBackService feedBackService;
	@Resource
	private IShopConfigService shopConfigService;
	@Resource
	private IPlanChapterConfigService PlanChapterService;
	@Resource
	private IPushService pushService;
	@Resource
	private ICoinsService coinsService;
	@Resource
	private IAdvertisementService advertisementService;
	@Resource
	private OSSUtil oss;

	@RequestMapping("/{method}/{page}")
	public ModelAndView view(HttpServletRequest req, HttpServletResponse resp, @PathVariable String method,@PathVariable String page
			, ModelMap modelMap){
		if (page.equals("book")){
		 	 List<BookConfigVo> ls = bookServcie.getBookConfigList();
		 	 modelMap.addAttribute("data", ls);
		} else if(page.equals("chapter")) {
			List<ChapterConfigVo> ls = chapterService.getChapterConfigList();
			 modelMap.addAttribute("data", ls);
		} else if(page.equals("level")) {
			List<StageConfigVo> ls = stageConfigService.getStageConfigList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("master")) {
			List<ExpertReadingVo> ls = expertService.getExpertReadingList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("mean")) {
			List<ExplainConfigVo> ls = explainService.getExplainConfigList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("plan")) {
			List<PlanConfigVo> ls = planConfigService.getPlanConfigList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("prop")) {
			List<PropertyConfigVo> ls = propertyConfigService.getPropertyConfigList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("region")) {
			List<DistrictVo> ls = districtService.getDistrictList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("story")) {
			List<StoryConfigVo> ls = storyService.getStoryConfigList();
			modelMap.addAttribute("data", ls);
		} else if(page.equals("tapes")) {
			List<RecordConfigVo> ls = recordServcie.getRecordConfigList();
			modelMap.addAttribute("data",ls);
		} else if(page.equals("member")) {
			List<UserVo> ls = userService.getUserList();
			modelMap.addAttribute("data",ls);
		} else if(page.equals("publish")) {
			List<PublishLogsVo> ls = publishService.getPublishLogs();
			modelMap.addAttribute("data",ls);
		} else if(page.equals("resource")){
			List<ResourceVo> ls = resourceService.getResourceList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("report")){
			List<ReportVo> ls = reportService.getReportList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("feedback")){
			List<FeedBackVo> ls = feedBackService.getFeedBackList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("shopConfig")){
			List<ShopConfigVo> ls = shopConfigService.getShopConfigList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("planChapter")){
			List<PlanChapterConfigVo> ls = 	PlanChapterService.getPlanChapterList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("push")){
			List<PushVo> ls = 	pushService.getPushList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("coinsConfig")){
			List<CoinsVo> ls = 	coinsService.getCoinsList();
			modelMap.addAttribute("data",ls);
		}else if(page.equals("advertisementConfig")){
			List<AdvertisementVo> ls = 	advertisementService.getAdvertisementList();
			modelMap.addAttribute("data",ls);
		}
		return new ModelAndView(method,modelMap);
	}
	/**
	 * 分享页跳转
	 * @param req
	 * @param resp 
	 * @param page
	 * @return
	 */
	@RequestMapping("/share/{page}")
	public String sharePage(HttpServletRequest req, HttpServletResponse resp,@PathVariable String page){
		return page;
	}
	@RequestMapping("/download/{page}")
	public ModelAndView download(HttpServletRequest req, HttpServletResponse resp,@PathVariable String page){
		String apk = oss.getUrl("bykj-gx-oss-bucket1", "guoxue.apk", new Date(new Date().getTime() + 3600 * 1000 * 24));
		String ios =  oss.getUrl("bykj-gx-oss-bucket1", "guoxue.ipa", new Date(new Date().getTime() + 3600 * 1000 * 24));
		JSONObject obj = new JSONObject();
		obj.put("apk", apk);
		obj.put("ipa", ios);
		return new ModelAndView(page, obj);
	}
}
